import React, { } from 'react'

import { Switch, Route, Redirect, withRouter } from 'react-router-dom'
import store from '../../redux/store'
import { Layout } from 'antd'
import Menu from '../../components/menu/Menu'
import TopHeader from '../../components/header/Header'
import Home from './home/Home'
import UserManage from './user-manage/UserManage'
import RoleList from './right-manage/role-list/RoleList'
import RightList from './right-manage/right-list/RightList'
import Nopermission from './nopermission/Nopermission'
import Login from '../login/Login'
import './newSandBox.css'
const { Content } = Layout

function NewSandBox (props) {

  // 判断用户是否登录
  if (!store.getState().userInfo) {
    props.history.go(-1)
    return <Login />
  }

  const { role: { rights } } = store.getState().userInfo[0]
  // 判断当前跳转的网址是否为当前用户所有的权限
  if (!rights.includes(props.location.pathname)) {
    props.history.go(-1)
  }
  return (
    <Layout>
      <Menu></Menu>
      <Layout className="site-layout">
        <TopHeader></TopHeader>
        <Content
          className="site-layout-background"
          style={{
            margin: '24px 16px',
            padding: 24,
            minHeight: 280
          }}>
          <Switch>
            <Route path='/home' component={Home}></Route>
            <Route path='/user-manage/list' component={UserManage}></Route>
            <Route path='/right-manage/role/list' component={RoleList}></Route>
            <Route path='/right-manage/right/list' component={RightList}></Route>
            <Route path='/home' component={Home}></Route>
            <Redirect from="/" to="/home" exact></Redirect>
            <Route path="*" component={Nopermission}></Route>
          </Switch>
        </Content>
      </Layout>
    </Layout>
  )
}
export default withRouter(NewSandBox)